import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class Test02 {


    public static Long getMax(Long[] arr,int left,int right){
        long[] acc = new long[2];
        if(left==arr.length){
            return 0L;
        }
        Hashtable<Integer,Integer> hashtable = new Hashtable<>();
        HashMap<Integer,Integer> map = new HashMap<>();
        HashSet<Integer> set = new HashSet<>();

       for(Map.Entry<Integer,Integer> entry:map.entrySet()){

       }

       Vector<Integer> vector = new Vector<>();
       vector.add(1);
       vector.add(2);
        System.out.println(vector);
        ConcurrentHashMap<Integer,Integer> concurrentHashMap = new ConcurrentHashMap<>();
        CopyOnWriteArrayList<Integer> copyOnWriteArrayList = new CopyOnWriteArrayList<>();

        long max = arr[left];
        long min = arr[left];
        for(int i = left;i<right+1;i++){
            if(max<arr[i]){
                max = arr[i];
            }
            if(min>arr[i]){
                min = arr[i];
            }
        }
        acc[0] = max;
        acc[1] = min;
        return max-min;
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Long[] arr = new Long[n];
        Long[] acc = new Long[n];
        for(int i = 0;i<arr.length;i++){
            arr[i] = in.nextLong();
        }
        for(int i = 1;i<arr.length;i++){

            acc[i] = Math.abs(getMax(arr,0,i)-getMax(arr,i+1,arr.length-1));
        }
Long[] app = new Long[acc.length-1];
       System.arraycopy(acc,1,app,0,app.length);
        PriorityQueue<Long> queue = new PriorityQueue<>();
        for(int i = 0;i<app.length;i++){
            queue.add(app[i]);
        }
        System.out.println(queue.peek());
    }

    public static Long getTime(Long x,Long y){

        return(y*x+(y)*(y-1)/2);
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
         int n = in.nextInt();
         Long[][] arr = new Long[n][2];
         Long[] acc = new Long[n];
        for(int i = 0;i< arr.length;i++){
            for(int j = 0;j<arr[0].length;j++){
                arr[i][j] = in.nextLong();
            }
        }

        for(int i = 0;i<arr.length;i++){
            if(arr[i][0]+1>=arr[i][1]){
                acc[i] = getTime(arr[i][0],arr[i][1]);
            }else{
                Long sum = getTime(arr[i][0],arr[i][0]+1);
                Long x = arr[i][0]*2;
                Long y = arr[i][1]-arr[i][0]-1;
                Long tmp = x*y;
                acc[i] = tmp+sum;
            }
        }
       for(int i = 0;i<n;i++){
           System.out.println(acc[i]);
       }

    }
}
